In [1]:
import pandas as pd
import matplotlib.pyplot as plt
import plotly as py
from plotly.offline import iplot
import cufflinks as cf
%matplotlib inline
In [2]:
cf.go_offline()
cf.set_config_file(offline=False, world_readable=True)
py.offline.init_notebook_mode()
In [3]:
df_matches=pd.read_csv('E:/Projects/IPL_Project/data/matches.csv',index_col='id',parse_dates=['date'])
In [4]:
df_matches
Out[4]:
season city date team1 team2 toss_winner toss_decision result dl_applied winner win_by_runs win_by_wickets player_of_match venue umpire1 umpire2 umpire3
id
1 2017 Hyderabad 2017-04-05 Sunrisers Hyderabad Royal Challengers Bangalore Royal Challengers Bangalore field normal 0 Sunrisers Hyderabad 35 0 Yuvraj Singh Rajiv Gandhi International Stadium, Uppal AY Dandekar NJ Llong NaN
2 2017 Pune 2017-04-06 Mumbai Indians Rising Pune Supergiant Rising Pune Supergiant field normal 0 Rising Pune Supergiant 0 7 SPD Smith Maharashtra Cricket Association Stadium A Nand Kishore S Ravi NaN
3 2017 Rajkot 2017-04-07 Gujarat Lions Kolkata Knight Riders Kolkata Knight Riders field normal 0 Kolkata Knight Riders 0 10 CA Lynn Saurashtra Cricket Association Stadium Nitin Menon CK Nandan NaN
4 2017 Indore 2017-04-08 Rising Pune Supergiant Kings XI Punjab Kings XI Punjab field normal 0 Kings XI Punjab 0 6 GJ Maxwell Holkar Cricket Stadium AK Chaudhary C Shamshuddin NaN
5 2017 Bangalore 2017-04-08 Royal Challengers Bangalore Delhi Daredevils Royal Challengers Bangalore bat normal 0 Royal Challengers Bangalore 15 0 KM Jadhav M Chinnaswamy Stadium NaN NaN NaN
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
632 2016 Raipur 2016-05-22 Delhi Daredevils Royal Challengers Bangalore Royal Challengers Bangalore field normal 0 Royal Challengers Bangalore 0 6 V Kohli Shaheed Veer Narayan Singh International Stadium A Nand Kishore BNJ Oxenford NaN
633 2016 Bangalore 2016-05-24 Gujarat Lions Royal Challengers Bangalore Royal Challengers Bangalore field normal 0 Royal Challengers Bangalore 0 4 AB de Villiers M Chinnaswamy Stadium AK Chaudhary HDPK Dharmasena NaN
634 2016 Delhi 2016-05-25 Sunrisers Hyderabad Kolkata Knight Riders Kolkata Knight Riders field normal 0 Sunrisers Hyderabad 22 0 MC Henriques Feroz Shah Kotla M Erasmus C Shamshuddin NaN
635 2016 Delhi 2016-05-27 Gujarat Lions Sunrisers Hyderabad Sunrisers Hyderabad field normal 0 Sunrisers Hyderabad 0 4 DA Warner Feroz Shah Kotla M Erasmus CK Nandan NaN
636 2016 Bangalore 2016-05-29 Sunrisers Hyderabad Royal Challengers Bangalore Sunrisers Hyderabad bat normal 0 Sunrisers Hyderabad 8 0 BCJ Cutting M Chinnaswamy Stadium HDPK Dharmasena BNJ Oxenford NaN

636 rows × 17 columns

In [5]:
no_result_matches=df_matches['winner'].isnull().sum()
no_result_matches
Out[5]:
3
In [6]:
winslost=df_matches[["team1","team2","winner"]]
winslost
Out[6]:
team1 team2 winner
id
1 Sunrisers Hyderabad Royal Challengers Bangalore Sunrisers Hyderabad
2 Mumbai Indians Rising Pune Supergiant Rising Pune Supergiant
3 Gujarat Lions Kolkata Knight Riders Kolkata Knight Riders
4 Rising Pune Supergiant Kings XI Punjab Kings XI Punjab
5 Royal Challengers Bangalore Delhi Daredevils Royal Challengers Bangalore
... ... ... ...
632 Delhi Daredevils Royal Challengers Bangalore Royal Challengers Bangalore
633 Gujarat Lions Royal Challengers Bangalore Royal Challengers Bangalore
634 Sunrisers Hyderabad Kolkata Knight Riders Sunrisers Hyderabad
635 Gujarat Lions Sunrisers Hyderabad Sunrisers Hyderabad
636 Sunrisers Hyderabad Royal Challengers Bangalore Sunrisers Hyderabad

636 rows × 3 columns

In [7]:
winslost['looser']=winslost.apply(lambda x:(x['team2'] if x['team1'] ==x['winner'] else x['team1']),axis=1)
winslost['looser']
Out[7]:
id
1      Royal Challengers Bangalore
2                   Mumbai Indians
3                    Gujarat Lions
4           Rising Pune Supergiant
5                 Delhi Daredevils
                  ...             
632               Delhi Daredevils
633                  Gujarat Lions
634          Kolkata Knight Riders
635                  Gujarat Lions
636    Royal Challengers Bangalore
Name: looser, Length: 636, dtype: object
In [8]:
wins=winslost['winner'].value_counts()
losses=winslost['looser'].value_counts()
In [9]:
losses
Out[9]:
Delhi Daredevils               85
Royal Challengers Bangalore    78
Kings XI Punjab                78
Kolkata Knight Riders          71
Mumbai Indians                 65
Rajasthan Royals               54
Chennai Super Kings            52
Deccan Chargers                46
Sunrisers Hyderabad            34
Pune Warriors                  33
Gujarat Lions                  17
Rising Pune Supergiants         9
Kochi Tuskers Kerala            8
Rising Pune Supergiant          6
Name: looser, dtype: int64
In [10]:
wins
Out[10]:
Mumbai Indians                 92
Chennai Super Kings            79
Kolkata Knight Riders          77
Royal Challengers Bangalore    73
Kings XI Punjab                70
Rajasthan Royals               63
Delhi Daredevils               62
Sunrisers Hyderabad            42
Deccan Chargers                29
Gujarat Lions                  13
Pune Warriors                  12
Rising Pune Supergiant         10
Kochi Tuskers Kerala            6
Rising Pune Supergiants         5
Name: winner, dtype: int64
In [11]:
wins.iplot(kind='bar',xTitle='Team',yTitle='Count',title='Winning count')
In [12]:
losses.iplot(kind='bar',xTitle='Team',yTitle='Count',title='Loosing count')
In [13]:
mom=df_matches['player_of_match'].value_counts()
In [14]:
mom
Out[14]:
CH Gayle           18
YK Pathan          16
AB de Villiers     15
DA Warner          15
RG Sharma          14
                   ..
KMDN Kulasekara     1
Z Khan              1
TM Dilshan          1
SM Katich           1
JD Ryder            1
Name: player_of_match, Length: 201, dtype: int64
In [15]:
mom[:20].iplot(kind='bar',xTitle='Player',yTitle='Count',title='Top 20 MOM')
In [16]:
## Matches hosted in each city
In [17]:
city=df_matches['city'].value_counts()
city
Out[17]:
Mumbai            85
Bangalore         66
Kolkata           61
Delhi             60
Hyderabad         49
Chennai           48
Chandigarh        46
Jaipur            33
Pune              32
Durban            15
Centurion         12
Ahmedabad         12
Visakhapatnam     11
Rajkot            10
Dharamsala         9
Johannesburg       8
Port Elizabeth     7
Cape Town          7
Cuttack            7
Abu Dhabi          7
Ranchi             7
Raipur             6
Sharjah            6
Indore             5
Kochi              5
Kanpur             4
Kimberley          3
East London        3
Nagpur             3
Bloemfontein       2
Name: city, dtype: int64
In [18]:
city[:20].iplot(kind='bar')
In [19]:
stadium=df_matches['venue'].value_counts()
stadium
Out[19]:
M Chinnaswamy Stadium                                   66
Eden Gardens                                            61
Feroz Shah Kotla                                        60
Wankhede Stadium                                        57
Rajiv Gandhi International Stadium, Uppal               49
MA Chidambaram Stadium, Chepauk                         48
Punjab Cricket Association Stadium, Mohali              35
Sawai Mansingh Stadium                                  33
Subrata Roy Sahara Stadium                              17
Dr DY Patil Sports Academy                              17
Maharashtra Cricket Association Stadium                 15
Kingsmead                                               15
SuperSport Park                                         12
Sardar Patel Stadium, Motera                            12
Dr. Y.S. Rajasekhara Reddy ACA-VDCA Cricket Stadium     11
Punjab Cricket Association IS Bindra Stadium, Mohali    11
Brabourne Stadium                                       11
Saurashtra Cricket Association Stadium                  10
Himachal Pradesh Cricket Association Stadium             9
New Wanderers Stadium                                    8
Sheikh Zayed Stadium                                     7
Dubai International Cricket Stadium                      7
St George's Park                                         7
Barabati Stadium                                         7
JSCA International Stadium Complex                       7
Newlands                                                 7
Shaheed Veer Narayan Singh International Stadium         6
Sharjah Cricket Stadium                                  6
Holkar Cricket Stadium                                   5
Nehru Stadium                                            5
Green Park                                               4
Vidarbha Cricket Association Stadium, Jamtha             3
Buffalo Park                                             3
De Beers Diamond Oval                                    3
OUTsurance Oval                                          2
Name: venue, dtype: int64
In [20]:
stadium[:20].iplot(kind='bar')
In [21]:
##Particularly seeing the match up between MI and CSK
In [22]:
def get_micsk(team1,team2):
    teams=["Chennai Super Kings","Mumbai Indians"]
    if team1 in teams and team2 in teams:
        return True
    else:
        return False
    
In [23]:
matchups=[]
for row in df_matches.iterrows():
    temp=get_micsk(row[1]['team1'],row[1]['team2'])
    matchups.append(temp)
In [24]:
sum(matchups)
Out[24]:
22
In [25]:
micsk=df_matches[matchups]
micsk.head()
Out[25]:
season city date team1 team2 toss_winner toss_decision result dl_applied winner win_by_runs win_by_wickets player_of_match venue umpire1 umpire2 umpire3
id
67 2008 Chennai 2008-04-23 Chennai Super Kings Mumbai Indians Mumbai Indians field normal 0 Chennai Super Kings 6 0 ML Hayden MA Chidambaram Stadium, Chepauk DJ Harper GA Pratapkumar NaN
96 2008 Mumbai 2008-05-14 Chennai Super Kings Mumbai Indians Mumbai Indians field normal 0 Mumbai Indians 0 9 ST Jayasuriya Wankhede Stadium BR Doctrove AM Saheba NaN
118 2009 Cape Town 2009-04-18 Mumbai Indians Chennai Super Kings Chennai Super Kings field normal 0 Mumbai Indians 19 0 SR Tendulkar Newlands BR Doctrove K Hariharan NaN
162 2009 Port Elizabeth 2009-05-16 Mumbai Indians Chennai Super Kings Mumbai Indians bat normal 0 Chennai Super Kings 0 7 ML Hayden St George's Park SK Tarapore SJA Taufel NaN
194 2010 Mumbai 2010-03-25 Chennai Super Kings Mumbai Indians Mumbai Indians field normal 0 Mumbai Indians 0 5 SR Tendulkar Brabourne Stadium BF Bowden AM Saheba NaN
In [26]:
micsk['winner'].value_counts().iplot(kind='bar')
In [27]:
micsk['player_of_match'].value_counts().iplot(kind='bar')
In [ ]: